#! /usr/bin/make -f

# debian/rules
# Part of Debian ‘python-lockfile’ package.
#
# Copyright © 2009–2016 Ben Finney <bignose@debian.org>
# This is free software; you may copy, modify, and/or distribute this work
# under the terms of the Expat license as published by James Clark.
# No warranty expressed or implied.

export PYBUILD_NAME = lockfile
export PYBUILD_TEST_NOSE = 1

DOC_SRC_DIR = doc/source
DOC_HTML_DIR = doc/html

GENERATED_FILES += ${DOC_HTML_DIR}

# Send HTTP traffic to the “discard” service during packaging actions.
export http_proxy = http://127.0.1.1:9/
export https_proxy = ${http_proxy}

SPHINX = sphinx-build
SPHINX_OPTS = -N

%:
	dh $@ --with python2,python3,sphinxdoc --buildsystem=pybuild


.PHONY: get-packaged-orig-source
get-packaged-orig-source:
	$(uscan-download-source) --download-current-version

# Policy §4.9 strongly recommends the ‘get-orig-source’ target:
# “This target is optional, but providing it if possible is a good idea.”
#
# This target is an anomaly: per Policy §4.9, it fetches the *latest*
# upstream source, regardless of this package's version. To fetch the
# upstream source corresponding to this package's *declared* version
# in ‘debian/changelog’, use ‘get-packaged-orig-source’ instead.
.PHONY: get-orig-source
get-orig-source:
	$(uscan-download-source)

get-orig-source get-packaged-orig-source: http_proxy =
get-orig-source get-packaged-orig-source: makefile_dir = $(abspath $(dir $(firstword ${MAKEFILE_LIST})))
get-orig-source get-packaged-orig-source: package_dir = $(abspath $(dir ${makefile_dir}))

define uscan-download-source
	uscan --noconf --verbose \
	    --force-download \
	    --rename \
	    --destdir=$(CURDIR) \
	    --check-dirname-level=0 ${package_dir}
endef # uscan-download-source


.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	$(RM) -r ${GENERATED_FILES}
	dh_auto_clean

.PHONY: override_dh_auto_build
override_dh_auto_build:
	dh_auto_build
	$(SPHINX) ${SPHINX_OPTS} -bhtml ${DOC_SRC_DIR}/ ${DOC_HTML_DIR}/


# Local variables:
# mode: makefile
# coding: utf-8
# End:
# vim: filetype=make fileencoding=utf-8 :
